﻿/// <summary>
/// https://leetcode-cn.com/problems/container-with-most-water/
/// </summary>
public class Solution
{
    public int MaxArea(int[] heights)
    {
        int max = 0;

        int left = 0;
        int right = heights.Length - 1;
        for (; left < right;)
        {
            var leftValue = heights[left];
            var rightValue = heights[right];

            var leftValueIsSmaller = leftValue < rightValue;

            max = Math.Max(max, (right - left) * (leftValueIsSmaller ? leftValue : rightValue));

            var dValue = leftValueIsSmaller ? 1 : 0;
            left += dValue;
            right += dValue - 1;
        }

        return max;
    }
}
/* 下方案超时
public class Solution
{
    private IEnumerable<(int x, int y)> GetXsAndYsAfter(int[] heights, int xStart)
    {
        for(; xStart < heights.Length;xStart++)
            yield return (xStart, heights[xStart]);
    }
    public int MaxArea(int[] heights)
    {
        var linq = from line1 in GetXsAndYsAfter(heights, 0)
                   from line2 in GetXsAndYsAfter(heights, line1.x + 1)
                   select (line2.x - line1.x) * Math.Min(line1.y, line2.y);
        return linq.Max();
    }
}
*/